import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/utils/ThemeConfig.dart';
import 'package:cbec_app/utils/logger.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

typedef _ClickCallBack = void Function(int selectIndex);

class LeftNavMenuItem extends StatefulWidget {
  ///菜单文字
  final String text;

  ///自身索引
  final int index;

  ///激活的索引
  final int? curIndex;

  ///点击时的回调
  final _ClickCallBack? onClick;

  ///左侧导航菜单item
  const LeftNavMenuItem(
      {super.key,
      required this.text,
      required this.index,
      this.curIndex = 0,
      this.onClick});

  @override
  State<StatefulWidget> createState() => _LeftNavMenuItemState();
}

class _LeftNavMenuItemState extends State<LeftNavMenuItem> {
  @override
  Widget build(BuildContext context) {
    return BaseInteractive(
      childWidget: Container(
        height: 50.h,
        color: Colors.transparent,
        child: Stack(
          children: [
            Positioned(
              top:16.h ,
                child: Container(
              width: 2.w,
              height: 18.h,
              color: widget.index==widget.curIndex?ThemeConfig.themeColor:Colors.transparent,
            )),
            Center(
              child: SizedBox(
                width: 98.w,
                child: Text(
                widget.text!,
                style: TextStyle(
                    fontSize: 13,
                    fontWeight:widget.index==widget.curIndex? FontWeight.bold:FontWeight.w500,
                    color: widget.index==widget.curIndex?ThemeConfig.themeColor:ThemeConfig.mainTextColor,
                    decoration: textNoDecoration()),
              ),
              ),
            )
          ],
        ),
      ),
      onClick: () {
        widget.onClick!(widget.index);
      },
    );
  }
}
